package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.user.User;
/**
 * 登录验证
 * @author 金晓凌
 *
 */

public class LoginServlet extends BaseServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		login(request, response);
		
	}
	private void login(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String path="login.jsp";
		try{
			String userid = request.getParameter("userid");
			String pwd = request.getParameter("pwd");
			User user = new User(userid);
			//查有此人
			if(user.getUserid() != null){
				//校验密码
				if(user.getPwd().equals(pwd)){
					path = "index.jsp";
					request.setAttribute("user", user);
					request.removeAttribute("error");
				}
			}else{
				request.setAttribute("error", "用户名或密码错误");
			}
			
		}catch(Exception e){
			e.printStackTrace();
			path = "error/500.jsp";
		}
		    //跳转页面
		    process(request, response, path);
		
	}


}
